<template>
	<view class="contain">
		<view class="address_item" v-for="item in addressList" :key="item.id">
			<view class="user_info" @tap="selectAddress(item)">
				<view class="name_c">
					<text class="name">{{item.name}}</text>
					<text class="default" v-if="item.defaultStatus == 1">默认</text>
				</view>
				<text>{{item.phoneNumber}}</text>
			</view>
			<navigator :url="computedUrl(item)" class="edit">
				<image src="../../../static/image/edit.png" mode="widthFix"></image>
			</navigator>
		</view>
		<navigator url="../addressReset/addressReset" class="btn">
			新增地址
		</navigator>
		
	</view>
</template>

<script>
	import request from '../../../api/request.js';
	export default {
		data() {
			return {
				addressList: [],
				type: ''
			};
		},
		computed: {
			computedUrl() {
				return function(item) {
					return "./../addressReset/addressReset?id=" + item.id
				}
			}
		},
		 onLoad(option) {
			this.type = option.type == 'select' ? option.type : '';
		},
		async onShow() {
			const res = await request({
				url: "/address/findAllAddress"
			})
			console.log(res);
			this.addressList = res.data.data.items;
		},
		methods: {
			selectAddress(item) {
				console.log(item);
			  if(this.type === 'select') {
				  uni.setStorageSync('selectAddress', item);
				  uni.navigateBack()
			  }	
			}			
		}
	}
</script>

<style lang="scss" scoped>
	page {
		padding-bottom: 200rpx;
	}

	.contain {
		.address_item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 200rpx;
			padding: 0 30rpx;
			border-bottom: 2rpx solid #999;

			.user_info {
				display: flex;
				flex-direction: column;
				justify-content: center;
				height: 100%;
				width: 550rpx;
				text {

					&:nth-child(2) {
						color: #999999;
						font-size: $uni-font-size-sm;
					}
				}

				.name_c {
					display: flex;
					align-items: center;

					.name {
						font-size: $uni-font-size-lg;

					}

					.default {
						display: block;
						width: 100rpx;
						height: 50rpx;
						line-height: 50rpx;
						border-radius: 10rpx;
						margin-left: 30rpx;
						text-align: center;
						background-color: $themeColor;
						color: #fff;
					}
				}
			}

			.edit {
				display: flex;
				align-items: center;
				justify-content: center;
				opacity: 0.7;
				height: 50%;
				padding: 0 20rpx;
				border-left: 3rpx solid #999999;

				image {
					width: 60rpx;
				}
			}
		}

		.btn {
			width: 600rpx;
			height: 100rpx;
			line-height: 100rpx;
			margin: auto;
			margin-top: 100rpx;
			border-radius: 50rpx;
			text-align: center;
			color: #fff;
			font-size: $uni-font-size-lg;
			background-color: $themeColor;
		}
	}
</style>
